import static org.junit.Assert.*;

import java.util.ArrayList;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zanateh.wargame.game.*;
import org.zanateh.wargame.game.hexagon.HexField;
import org.zanateh.wargame.game.hexagon.Hexagon;
import org.zanateh.wargame.game.hexagon.HexagonFactory;
import org.zanateh.wargame.game.hexagon.HexField.NotInitializedException;
import org.zanateh.wargame.game.hexagon.HexagonFactory.HexagonType;
import org.zanateh.wargame.game.moveevaluators.AdjacentMoveEvaluator;
import org.zanateh.wargame.game.moveevaluators.IMoveEvaluator;
import org.zanateh.wargame.game.moveevaluators.NoOtherSamePlayerOccupantsMoveEvaluator;
import org.zanateh.wargame.game.piece.Piece;

public class MoveEvaluatorTest {
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAllowAdjacentMoveEvaluator() throws NotInitializedException {
		HexField hf = new HexField(100,100);
		hf.generateHexField(10,10);
		Piece piece = new Piece();
		piece.setHex(hf.getHex(4, 4));
		IMoveEvaluator moveEvaluator = new AdjacentMoveEvaluator();
		moveEvaluator.onAddEvaluator(piece);
		Assert.assertTrue(moveEvaluator.allowMove(hf.getHex(4, 5)));
		Assert.assertTrue(moveEvaluator.allowMove(hf.getHex(3, 4)));
		Assert.assertFalse(moveEvaluator.allowMove(hf.getHex(8,8)));
	}
	
	@Test
	public void testRejectOccupiedHexMoveOnNoOtherOccupants() {
		Hexagon hex1 = HexagonFactory.createHexagon(HexagonType.TEST);
		
		Piece piece1 = new Piece();
		piece1.setHex(hex1);
		
		Piece piece2 = new Piece();
		
		IMoveEvaluator moveEvaluator = new NoOtherSamePlayerOccupantsMoveEvaluator();
		moveEvaluator.onAddEvaluator(piece2);
		Assert.assertFalse(moveEvaluator.allowMove(hex1));
		Assert.assertNotNull(moveEvaluator.getRejectedMessage());
	}
	
	
	
	@Test
	public void testAllowEmptyHexMoveOnNoOtherOccupants() {
		Hexagon hex1 = HexagonFactory.createHexagon(HexagonType.TEST);
		
		Piece piece1 = new Piece();
		
		IMoveEvaluator moveEvaluator = new NoOtherSamePlayerOccupantsMoveEvaluator();
		moveEvaluator.onAddEvaluator(piece1);
		Assert.assertTrue(moveEvaluator.allowMove(hex1));
	}
	
	@Test
	public void testRejectOccupiedHexMoveByExistingOccupant() {
		Hexagon hex1 = HexagonFactory.createHexagon(HexagonType.TEST);
		
		Piece piece1 = new Piece();
		IMoveEvaluator moveEvaluator = new NoOtherSamePlayerOccupantsMoveEvaluator();
		piece1.addMoveEvaluator(moveEvaluator);
		piece1.setHex(hex1);
		
		Piece piece2 = new Piece();
		
		Assert.assertFalse(moveEvaluator.allowAnotherPieceMove(piece2));
	}

}
